<script type="text/javascript">
function scaleImg(img, maxWidth, maxHeight) {
	var width = 0;
	var height = 0;
    var ratio = 1;
   
    width = jQuery(img).width(); 
	height = jQuery(img).height();
		
    if (width > maxWidth || height > maxHeight)	{
		if ((maxHeight / height) <= (maxWidth / width))	{			
			ratio = width / height; 
			height = maxHeight;
			width = maxHeight * ratio;
		} else {			
			ratio = height / width; 
			height = maxWidth * ratio ;
			width = maxWidth;
		}
	}
    
    if (height < maxHeight) {
    	var top = Math.round((maxHeight - height)/2);
    	jQuery(img).css("margin-top", top);
    }
	
    if (width < maxWidth) {
    	var left = Math.round((maxWidth - width)/2);
    	jQuery(img).css("margin-left", left);
    }
    jQuery(img).css("display", "block");
    jQuery(img).width(width);
    jQuery(img).height(height);   
}

function imagePreview(imgId, imgPreviewId) {
	var file = document.getElementById(imgId);
	var imgPreview = document.getElementById(imgPreviewId);
	if (file.files) {
		imgPreview.src = file.files.item(0).getAsDataURL();		
	} else {
		imgPreview.src = file.value;
	}
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function isDecimal(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode == 46) {
		return true;
	}				
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function checkSpecialCharacters(data) {
	var iChars = "!@#jQuery%^&*()+=-[]\\\';,./{}|\":<>?~_`"; 
	   for (var i = 0; i < data.length; i++) {
	  	if (iChars.indexOf(data.charAt(i)) != -1) {
	  	return false;
	  	}
	  }
	return true;   
}

function cancel(url) {
	  document.location = url;
}

function redirectToPage(url) {
	  document.location = url;
}

function submitForm(form){
	var jQueryform = jQuery("form[name='"+form+"']");
	jQueryform.submit();
}

var pickerOpts = {
		changeMonth: true,
	    changeYear: true,
		yearRange: "-80:+0",
		showOn: "both",
		buttonImage: "<%=request.getContextPath()%>/images/calendar.gif",
		buttonText: "Open datepicker",
		buttonImageOnly: true,
		dateFormat:"yy-mm-dd"
};

jQuery(document).ready(function(){
	jQuery("#arrow-img").click(function(){
		jQuery(".sub-menu").css("display","block");		 
	});	
    jQuery("#arrow-img").hover(
		  function () {
			  jQuery(".sub-menu").css("display","none");
		  },
		  function () {					  
		  }
	);       
});
</script>